﻿/**********************************************
 * 功能名称：作业成本分配查询
编写人：  杨莹
建立时间： 杨 2009年5月12日
说明：
加载页面时，列表显示有费用分配的作业中心列表。
选择会计期间，查询出当前作业中心的作业成本分配信息。
 **************************************************************/

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;
using System.Data.Linq;
using System.Collections.Generic;

namespace Hisun.View.ReportQuery
{
    public partial class Report_FYFPB : System.Web.UI.Page
    {
        HisunDBDataContext db = new HisunDBDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
           if(!IsPostBack)
           {
               AbcFullAccountPeriod MyFullAp = new AbcFullAccountPeriod();

               MyFullAp.FullAccountPeriodToDropdownlist(DropDownList_Year, DropDownList_Month, Application["accountPeriod"].ToString());

               var DropdownlistItems = (from a in db.VABC_Report_ActivityCostAllocation
                                       join b in db.TABC_DM_CostItems on a.成本细项ID equals b.成本细项ID
                                       select new
                                       {
                                           a.成本细项ID,
                                           b.成本细项名称

                                       }).Distinct();
               DropDownList_FeeItems.Items.Clear();

               foreach (var DropDownListItem in DropdownlistItems)
               {
                   DropDownList_FeeItems.Items.Add(new ListItem(DropDownListItem.成本细项名称, DropDownListItem.成本细项ID));
               }


           }
        }




        //protected void TreeView_CenterTree_SelectedNodeChanged(object sender, EventArgs e)
        //{
        //    string  MyCenterId = TreeView_CenterTree.SelectedNode.Value.ToString();
        //    Response.Redirect("Report_FYFPB_Detail.aspx?CenterId=" + MyCenterId+"&AccountPeriod="+TextBox_AccountPeriod.Text+"&CostItem="+DropDownList_FeeItems.SelectedValue.ToString());
      
        //}

        protected void Button_Query_Click(object sender, EventArgs e)
        {

            //var CurrentUserCenterId = (from a in db.TAbc_JS_Users where a.操作员ID == Session[ServerVars.sysSessionUserName].ToString() select new { a.责任部门ID }).Single();

            string AccountPeriod = DropDownList_Year.SelectedValue.ToString() + DropDownList_Month.SelectedValue.ToString(); ;
  
            string MyCostItem = DropDownList_FeeItems.SelectedValue.ToString();


            var IsValidString = from a in db.TABC_JS_AccountPeriods
                                where a.会计期间ID == AccountPeriod
                                select a;
            if (IsValidString.Count() == 0)
            {
                Response.Write("<Script>alert('会计期间不存在，请检查输入是否正确')</Script>");
                return;
            }
            else if (IsValidString.Count() == 1)
            {

                string CurrentUser = Session[ServerVars.sysSessionUserName].ToString();
                CostReport MyReport = new CostReport();
                string myHtmlReport = "";
                myHtmlReport = MyReport.WriteExcel_Report_FYFPB(1, MyCostItem, AccountPeriod, CurrentUser);
                Response.Redirect("/Report/UserReport/" + myHtmlReport + ".html");

            }
        }
    }
}
